public class MyQueue {
    static class ListNode{
        public int val;
        public ListNode prev;
        public ListNode next;

        public ListNode(int val){
            this.val = val;
        }
    }
    public ListNode head =null;
    public ListNode last = null;
    public int usedSize = 0;
    //添加一个节点
    public void offer(int val){
        ListNode node = new ListNode(val);
        if(IsEmpty()){
            head = last = node;
        }else{
            last.next = node;
            node.prev = last;
            last = node;
        }
        usedSize++;
    }
    //是否为空
    public boolean IsEmpty(){
        return usedSize==0;
    }
    //返回第一个数
    public int peek(){
        if(head==null){
            return -1;
        }
        return head.val;
    }
    public int poll(){
        if(head == null){
            return -1;
        }else{
            int val = head.val;
            head = head.next;
            if(head!=null) {
                head.prev = null;
            }
            usedSize--;
            return val;
        }
    }
}
